package com.ccod.mapper.mapper.core.utils;

import java.io.IOException;
import java.io.InputStream;
import java.net.URL;

/**
 * @author ccod
 * @date 2020-12-06 12:49
 **/
public class RefreshUtils {

    public static final String URL_PROTOCOL_FILE = "file";

    public static final String JAR_FILE_EXTENSION = ".jar";

    /**
     * jar内mapper不刷新
     *
     * @param url
     * @return
     */
    public static boolean isJarFileURL(URL url) {
        return (URL_PROTOCOL_FILE.equals(url.getProtocol()) &&
                url.getPath().toLowerCase().endsWith(JAR_FILE_EXTENSION));
    }

    /**
     * 断言
     *
     * @param object
     * @param message
     */
    public static void notNull(Object object, String message) {
        if (object == null) {
            throw new IllegalArgumentException(message);
        }
    }

    public static void close(InputStream inputStream){
        if(inputStream == null){
            return;
        }
        try {
            inputStream.close();
        } catch (IOException e) {
        }
    }

}
